package top.itaso.app.ui.slideshow;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import top.itaso.app.databinding.FragmentSlideshowBinding;
import top.itaso.lib.alog.ALog;


public class SlideshowFragment extends Fragment {
    private static final String TAG = "SlideshowFragment";

    private SlideshowViewModel slideshowViewModel;
    private FragmentSlideshowBinding binding;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ALog.vTag(TAG, "......");
    }

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        slideshowViewModel =
                new ViewModelProvider(this).get(SlideshowViewModel.class);

        binding = FragmentSlideshowBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        final TextView textView = binding.textSlideshow;
        slideshowViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });
        return root;
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        ALog.vTag(TAG, "savedInstanceState: %s", savedInstanceState);
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onStart() {
        super.onStart();
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onResume() {
        super.onResume();
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onPause() {
        super.onPause();
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onStop() {
        super.onStop();
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ALog.vTag(TAG, "......");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        ALog.vTag(TAG, "......");
    }
}